/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quan;

import javax.swing.JScrollPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author Quannk
 */
public class QScrollPane extends JScrollPane {

    private boolean synchronizedScroll;

    public boolean isSynchronizedScroll() {
        return synchronizedScroll;
    }

    public void setSynchronizedScroll(boolean synchronizedScroll) {
        this.synchronizedScroll = synchronizedScroll;
    }
    private QDesktopPane desktopPane;

    public QDesktopPane getDesktopPane() {
        return desktopPane;
    }

    public void setDesktopPane(QDesktopPane desktopPane) {
        this.desktopPane = desktopPane;
    }

    public QScrollPane() {
        getViewport().addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                if (!synchronizedScroll && desktopPane != null && desktopPane.getOverviewPanel() != null) {
                    desktopPane.getOverviewPanel().setVisibleRect(getViewport().getViewRect());
                }
            }
        });
    }
}
